package model;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created by admin
 * <p>
 * Date :2020/10/13
 * <p>
 * Description : 单张扑克牌
 * <p>
 * Version :1.0
 */
public final class PockerCard implements Comparable<PockerCard> {
    private static final Logger logger = LoggerFactory.getLogger(PockerCard.class);

    private int index;

    /**
     * 类型
     */
    private PockerType type;

    /**
     * 值
     */
    private PockerPoint value;


    public PockerCard(int index, PockerType type, PockerPoint value) {
        this.index = index;
        this.type = type;
        this.value = value;
    }

    public PockerCard(PockerType type, PockerPoint value) {
        this.type = type;
        this.value = value;
    }

    public int getIndex() {
        return index;
    }

    public PockerType getType() {
        return type;
    }

    public PockerPoint getValue() {
        return value;
    }

    @Override
    public String toString() {
        return '{' +type.name + "" + value.name + '}';
    }

    @Override
    public int compareTo(PockerCard o) {
        int i = this.getValue().point - o.getValue().point;
        if(i == 0){
            return this.getType().type - o.getType().type;
        }
        return i ;
    }

    /**
     * 扑克牌类型 黑红梅方
     */
    public enum PockerType{
        SPADE(4, "黑桃"), HEART(3, "红桃"), CLUB(2, "梅花"), DIAMOND(1, "方片");

        private int type;

        private String name;

        PockerType(int type, String name) {
            this.type = type;
            this.name = name;
        }

        public int getType() {
            return type;
        }

        public String getName() {
            return name;
        }
    }

    /**
     * 扑克牌值 2-A
     */
    public enum PockerPoint {
        POCKER_A(12,"A"),
        POCKER_2(0, "2"),
        POCKER_3(1, "3"),
        POCKER_4(2, "4"),
        POCKER_5(3, "5"),
        POCKER_6(4, "6"),
        POCKER_7(5, "7"),
        POCKER_8(6, "8"),
        POCKER_9(7, "9"),
        POCKER_10(8, "10"),
        POCKER_J(9, "J"),
        POCKER_Q(10, "Q"),
        POCKER_K(11, "K");

        private int point;

        private String name;

        PockerPoint(int value, String name) {
            this.point = value;
            this.name = name;
        }

        public static PockerPoint fromValue(int value) {
            for (PockerPoint v : PockerPoint.values()) {
                if (v.point == value) {
                    return v;
                }
            }
            return null;
        }

        public int getPoint() {
            return point;
        }

        public String getName() {
            return name;
        }
    }

}
